/**
 * @author LKQ
 * @date 2022/1/14 15:01
 * @description 滑动窗口 O(N) start 和 end 最多移动 n 次
 */
public class Solution {
    public static void main(String[] args) {

    }
    public int minSubArrayLen(int target, int[] nums) {
        int n = nums.length;
        if (n == 0) {
            return 0;
        }
        int start = 0, end = 0, sum = 0;
        int ans = Integer.MAX_VALUE;
        while (end < n) {
            sum += nums[end];
            while (sum >= target) {
                ans = Math.min(ans, end - start + 1);
                sum -= nums[start];
                start++;
            }
            end++;
        }
        return ans == Integer.MAX_VALUE ? 0 : ans;
    }
}
